package com.example.mobile2021606144ywr0506;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private TextView tvSupTitle;
    private RadioGroup radioGroup;
    private RadioButton radBtnGys1;
    private RadioButton radBtnGys2;
    private RadioButton radBtnGys3;
    private RadioButton radBtnGys4;
    private Button btnGYSSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();
        btnGYSSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId=radioGroup.getCheckedRadioButtonId();
                if (radBtnId!=-1){
                    RadioButton radioButton=findViewById(radBtnId);
                    String supplierName=radioButton.getText().toString();
                    Intent intent=new Intent();
                    intent.putExtra("supplier",supplierName);
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }
        });
    }

    private void initView() {
        tvSupTitle = (TextView) findViewById(R.id.tv_sup_title);
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        radBtnGys1 = (RadioButton) findViewById(R.id.rad_btn_gys1);
        radBtnGys2 = (RadioButton) findViewById(R.id.rad_btn_gys2);
        radBtnGys3 = (RadioButton) findViewById(R.id.rad_btn_gys3);
        radBtnGys4 = (RadioButton) findViewById(R.id.rad_btn_gys4);
        btnGYSSubmit = (Button) findViewById(R.id.btn_GYS_submit);
    }
}